package edu.xlh.travel.controller.admin;

import com.alibaba.fastjson.JSONArray;
import edu.xlh.travel.common.Result;
import edu.xlh.travel.pojo.Notice;
import edu.xlh.travel.pojo.querypojo.QueryCheckTask;
import edu.xlh.travel.service.NoticeService;
import edu.xlh.travel.syslog.annontion.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;

@Controller
@RequestMapping("/notice")
public class NoticeController {
    @Autowired
    private NoticeService noticeService;

    /*
    * get laster four notice
    * */
    @Log("获取最近的公告")
    @RequestMapping("/getlasterNotice")
    @ResponseBody
    public Result getlasterNotice(HttpSession session) {
        return noticeService.getlasterNotice(session);
    }

    /*
    * to issuing notice Page
    * */
    @RequestMapping("/toNoticeIssuedPage")
    public String toNoticeIssuedPage() {
        return "admin/noticemanage/noticeIssued";
    }

    /*
    * issuing notice
    * */
    @Log("发布公告")
    @RequestMapping("/issuedNotice")
    @ResponseBody
    public Result issuedNotice(@RequestBody HashMap HashMap , HttpSession session) {
        return noticeService.issuedNotice(HashMap , session);
    }

    /*
    to noticeList page
    * */
    @Log("跳转公告列表页面")
    @RequestMapping("/noticeList")
    public String noticeList() {
        return "admin/noticemanage/noticeList";
    }

    /*
    * find Notice
    * */
    @Log("查询所有的公告")
    @RequestMapping("/findAllNotice")
    @ResponseBody
    public Result findAllNotice(int page  , int limit , HttpSession session) {
        return noticeService.findAllNotice(page , limit , session);
    }
    /*
     * edit Notice
     * */
    @Log("编辑公告")
    @RequestMapping("/edit/{id}")
    @ResponseBody
    public Result edit(@PathVariable("id")String id , @RequestBody Notice notice , HttpSession session) {
        return noticeService.edit(id , notice, session);
    }

    /*
     * delete notice by id
     * */
    @Log("根据id删除公告")
    @RequestMapping("/deleteById/{id}")
    @ResponseBody
    public Result deleteById(@PathVariable("id") String id , @RequestBody HashMap hashMap , HttpSession session) {
        return noticeService.deleteById(id , hashMap , session);
    }

    /*
     *
     * batch delete
     *  */
    @Log("批量删除公告")
    @RequestMapping("/batchDelete")
    @ResponseBody
    public Result batchDelete(@RequestBody JSONArray jsonArray , HttpSession session) {
        return noticeService.batchDelete(jsonArray ,session);
    }

    /*
    * query notice bny condition
    * */
    @Log("条件模糊查询公告")
    @RequestMapping("/QueryNoticeByCondition")
    @ResponseBody
    public Result QueryNoticeByCondition(Integer page, Integer limit, Notice notice , HttpSession session) {
        return noticeService.QueryNoticeByCondition(page , limit , notice ,session);
    }


    /*
     * to edit notice Page
     * */
    @Log("跳转公告编辑页面")
    @RequestMapping("/toNoticeIssuedPageWithDataById")
    public String toNoticeIssuedPageWithDataById(String id) {
        return "admin/noticemanage/noticeEdit";
    }

    /*
    * */
    @Log("根据id查询公告")
    @RequestMapping("/findById")
    @ResponseBody
    public Result findById(String id , HttpSession session) {
        return noticeService.findById(id , session);
    }

    /*
    *
    * */
    @Log("编辑公告")
    @RequestMapping("/editNotice/{noticeId}")
    @ResponseBody
    public Result editNotice(@PathVariable("noticeId") String noticeId , @RequestBody Notice notice , HttpSession session) {
        return noticeService.editNotice(noticeId , notice , session);
    }

}
